#!/bin/bash -e
# shellcheck source=meta-facebook/meta-minerva/recipes-minerva/plat-tool/files/minerva-common-functions
source /usr/libexec/minerva-common-functions

power_on_led_init() {
    systemctl start obmc-led-group-start@power_on.service
}

# set initial value for GPIO output pins
set_gpio PWREN_MTIA_BLADE1_EN_N 0
set_gpio PWREN_MTIA_BLADE2_EN_N 0
set_gpio PWREN_MTIA_BLADE3_EN_N 0
set_gpio PWREN_MTIA_BLADE4_EN_N 0
set_gpio PWREN_MTIA_BLADE5_EN_N 0
set_gpio PWREN_MTIA_BLADE6_EN_N 0
set_gpio PWREN_MTIA_BLADE7_EN_N 0
set_gpio PWREN_MTIA_BLADE8_EN_N 0
set_gpio PWREN_MTIA_BLADE9_EN_N 0
set_gpio PWREN_MTIA_BLADE10_EN_N 0
set_gpio PWREN_MTIA_BLADE11_EN_N 0
set_gpio PWREN_MTIA_BLADE12_EN_N 0
set_gpio PWREN_MTIA_BLADE13_EN_N 0
set_gpio PWREN_MTIA_BLADE14_EN_N 0
set_gpio PWREN_MTIA_BLADE15_EN_N 0
set_gpio PWREN_MTIA_BLADE16_EN_N 0

set_gpio PWREN_NW_BLADE1_EN_N 0
set_gpio PWREN_NW_BLADE2_EN_N 0
set_gpio PWREN_NW_BLADE3_EN_N 0
set_gpio PWREN_NW_BLADE4_EN_N 0
set_gpio PWREN_NW_BLADE5_EN_N 0
set_gpio PWREN_NW_BLADE6_EN_N 0

set_gpio PWREN_MTIA_BLADE1_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE2_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE3_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE4_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE5_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE6_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE7_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE8_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE9_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE10_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE11_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE12_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE13_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE14_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE15_HSC_EN_N 0
set_gpio PWREN_MTIA_BLADE16_HSC_EN_N 0

set_gpio PWREN_NW_BLADE1_HSC_EN_N 0
set_gpio PWREN_NW_BLADE2_HSC_EN_N 0
set_gpio PWREN_NW_BLADE3_HSC_EN_N 0
set_gpio PWREN_NW_BLADE4_HSC_EN_N 0
set_gpio PWREN_NW_BLADE5_HSC_EN_N 0
set_gpio PWREN_NW_BLADE6_HSC_EN_N 0

set_gpio PWREN_SGPIO_FCB_1_EN_N 0
set_gpio PWREN_SGPIO_FCB_2_EN_N 0
set_gpio PWREN_SGPIO_FCB_3_EN_N 0
set_gpio PWREN_SGPIO_FCB_4_EN_N 0
set_gpio PWREN_SGPIO_FCB_5_EN_N 0
set_gpio PWREN_SGPIO_FCB_6_EN_N 0

set_gpio FM_BMC_RST_RTCRST_R 0
set_gpio ERR_INJECT_CMM_PWR_FAIL_N 1

set_gpio RST_I2CRST_FCB_1_N 1
set_gpio RST_I2CRST_FCB_2_N 1
set_gpio RST_I2CRST_FCB_3_N 1
set_gpio RST_I2CRST_FCB_4_N 1
set_gpio RST_I2CRST_FCB_5_N 1
set_gpio RST_I2CRST_FCB_6_N 1

set_gpio FM_MDIO_SW_SEL 0
set_gpio FM_88E6393X_BIN_UPDATE_EN_N 1
# 0: open the valve, 1: close the valve
set_gpio WATER_VALVE_CLOSED_N 0

# The workaround is to disable GPIO passthrough,
# which is enabled by a hardware strap pin that is active high.
# This design is intended for a debug presence pin,
# so the default value is pulled high.
devmem 0x1e6e251c 32 0

power_on_led_init

exit 0
